<template>
    <div class="wiper">
        <Filter title="库存" :items="items" :model="condition" />
        <Table :buttons="buttons" :columns="columns" :data="data" :pagination="condition" />
    </div>
</template>
<script>
import { message, Modal } from "ant-design-vue";
import Filter from "@/components/Filter";
import Table from "@/components/Table";
import { getContainerDetail} from "@/api/inventory";
import {Base64} from 'js-base64';
import {
    ColumnProps, FilterItems, FilterCondition
} from "./config";

export default {
    name: 'inventoryDetail',
    data() {
        return {
            items: FilterItems,
            data: [{}],
            columns: ColumnProps,
            condition: {
              ...FilterCondition,
              onChange: (page, pageSize) => {
                this.condition.current = page;
                this.condition.pageSize = pageSize;
                this.load();
              }
            }
        }
    },
    components: {
        Filter,
        Table
    },
    mounted() {

        this._details(this.$route.query);
  
    },
    methods: {

                /**
         * 加载数据
         */
         load() {
            getContainerDetail({...this.condition, container: this.container}).then(res => {
                this.data = res.data.rows;
                this.condition.total = res.data.total;
            })
        },
        /**
             *
             * 查询详细
             */
        _details(query){
            this.container = JSON.parse(Base64.decode(Object.keys(query).map(item => query[item]).join(""))).id;
            getContainerDetail({...this.condition, container: this.container}).then(res => {
                this.data = res.data.rows;
                this.condition.total = res.data.total;
            })
        },
       
        /**
         * 跳转路由
         */
        goRoute(ids) {
            return new Promise((resolve, reject) => {
                if (ids.length == 0) {
                    return reject("至少要选择一条数据")
                }
                if (ids.length > 1) {
                    return reject("只能选择一条数据")
                }
                return resolve();
            })
        },
        /**
         * 刷新
         */
        // refresh(){
        //     this.load();
        // },

        _rename(list) {
            return list.map(item => {
                return { label: item.name, value: item.id, children: this._rename(item.children) }
            });
        },

    }
}
</script>
<style></style>
